﻿namespace Demo;

internal class Program
{
    //public static Type GetTypeByAssemblyAndTypeName(string assemblyFullName, string typeFullName)
    //{
    //    try
    //    {
    //        // 1. 解析程序集全名
    //        var assemblyName = new AssemblyName(assemblyFullName);

    //        // 2. 加载目标程序集
    //        var assembly = Assembly.Load(assemblyName);

    //        // 3. 从程序集中获取类型
    //        var type = assembly.GetType(typeFullName);

    //        if (type == null)
    //            throw new TypeLoadException("Type '{typeFullName}' not found in assembly '{assembly.FullName}'.");

    //        return type;
    //    }
    //    catch (FileNotFoundException ex)
    //    {
    //        throw new InvalidOperationException("Assembly not found: {ex.FileName}", ex);
    //    }
    //    catch (BadImageFormatException ex)
    //    {
    //        throw new InvalidOperationException("Invalid assembly format: {ex.Message}", ex);
    //    }
    //}

    private static void Main(string[] args)
    {
        for (var i = 0; i < 10; i++)
        {
            if (i == 5) i++;
            Console.WriteLine(i);
        }


        //var testData = "123456789"u8.ToArray();

        //Console.WriteLine($"CCITT-FALSE: 0x{Crc16.Compute(testData):X4}"); // 0x29B1
        //Console.WriteLine($"MODBUS:      0x{Crc16.Compute(testData, Crc16.Algorithm.Modbus):X4}"); // 0x4B37
        //Console.WriteLine($"XMODEM:      0x{Crc16.Compute(testData, Crc16.Algorithm.Xmodem):X4}"); // 0x31C3
        //Console.WriteLine($"KERMIT:      0x{Crc16.Compute(testData, Crc16.Algorithm.Kermit):X4}"); // 0x2189
        //Console.WriteLine($"IBM:         0x{Crc16.Compute(testData, Crc16.Algorithm.Ibm):X4}"); // 0xBB3D


        //Console.WriteLine("-------------------------------------------------------------------------------------");
        //Console.WriteLine($"CCITT-FALSE: 0x{Crc1611.Compute(testData):X4}"); // 0x29B1
        //Console.WriteLine($"MODBUS:      0x{Crc1611.Compute(testData, Crc1611.Algorithm.Modbus):X4}"); // 0x4B37
        //Console.WriteLine($"XMODEM:      0x{Crc1611.Compute(testData, Crc1611.Algorithm.Xmodem):X4}"); // 0x31C3
        //Console.WriteLine($"KERMIT:      0x{Crc1611.Compute(testData, Crc1611.Algorithm.Kermit):X4}"); // 0x2189
        //Console.WriteLine($"IBM SDLC:         0x{Crc1611.Compute(testData, Crc1611.Algorithm.IbmSdlc):X4}"); // 0xBB3D
        //Crc1611.DebugTable(Crc1611.Algorithm.Modbus);
        // var name = WebUtility.HtmlEncode(@"<\./>");
        //var AA = Pro.A;
        //var typee = AA.GetDescription();

        //Type listType = typeof(List<int>);
        //var Assembly = listType.Assembly;
        //var name = Assembly.FullName;
        //var fullName = listType.FullName;  // 输出 "System.Collections.Generic.List`1[[System.Int32, ...]]"
        //                                   //ReadOnlySpan<byte> data = [0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39];
        //                                   //var cec16 = data.GetCrc16Ccitt();
        //byte[] testData = "123456789"u8.ToArray();

        //ushort crc = Crc16Kermit.ComputeChecksum(testData);
        //Console.WriteLine(crc == 0x2189 ? "验证通过" : "验证失败");
        //// 1. 解析程序集全名
        //var assemblyName = new AssemblyName(name);

        //// 2. 加载目标程序集
        //Assembly assembly = Assembly.Load(assemblyName);

        //// 3. 从程序集中获取类型
        //Type type = assembly.GetType(fullName);
        //Type.GetType(fullName, name);


        //Console.WriteLine(name);
        //var a = Tuple.Create(1, "a", 3);
        //var b = Tuple.Create(1, "a", 3);
        //Console.WriteLine(a.GetHashCode());
        //Console.WriteLine(b.GetHashCode());
        //Console.WriteLine(a == b);
        //var data = new byte[5];
        //data[0] = 1;
        //data[1] = 2;
        //data[2] = 3;
        //data[3] = 4;
        //data[4] = 5;
        //Span<byte> bytes = data;
        //var cc1 = bytes[..^2];

        //var cc = bytes.Get P inn able Reference();
        //var data1 = Unsafe.As<byte[]>(cc);

        //var pipe = new Pipe();
        //var reader = pipe.Reader;
        //var writer = pipe.Writer;


        //writer.Write(new byte[] { 1, 2 });
        // var result = writer.FlushAsync().GetAwaiter().GetResult();
        //pipe.Reader.Complete();
        //pipe.Writer.Complete();
        //pipe.Reset();

        //memory = writer.GetMemory(10);
        //memory.Span[0] = 5;
        //memory.Span[1] = 6;
        //writer.Advance(2);

        //ReadResult result1 = reader.ReadAsync().GetAwaiter().GetResult();
        //ReadOnlySequence<byte> buffer = result1.Buffer;
        //var aac = buffer.First.Length;
        //pipe.Reader.Complete();
        //pipe.Writer.Complete();
        //pipe.Reset();
    }
}
// 双表生成工具类